package com.ruoyi.kong.utils;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.kong.domain.KongxSystemProfile;
import com.ruoyi.common.exception.kong.KongServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import static com.ruoyi.common.utils.DictUtils.getKongCacheKey;

/**
 * kong 网关工具类
 */
@Component
public class KongActiveProfileUtil {

    @Autowired
    private RedisCache redisCache;

    public  String getKongServerUrl(){
        KongxSystemProfile _kongProfile = StringUtils.cast(redisCache.getCacheObject(getKongCacheKey()));
        if(ObjectUtils.isEmpty(_kongProfile)){
            throw new KongServiceException("无法获网关配置参数，请重新激活");
        }
        return  _kongProfile.getUrl();
    }


}
